package com.xmut.mall.coupon.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xmut.mall.coupon.enums.PromotionsStatusEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName("li_coupon_activity")
public class CouponActivityEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId(type = IdType.INPUT)
    private Long id;
    /**
     *
     */
    private Date createTime;
    /**
     *
     */
    private Date endTime;
    /**
     *
     */
    private String promotionName;
    /**
     *
     */
    private Date startTime;
    /**
     *
     */
    private Long storeId;
    /**
     *
     */
    private String storeName;
    /**
     *
     */
    private String activityScope;
    /**
     *
     */
    private String activityScopeInfo;
    /**
     *
     */
    private String couponActivityType;
    /**
     * 范围关联的ID
     */
    private String scopeId;
    /**
     * 关联范围类型
     */
    private String scopeType;

    /**
     * @return 满减活动的状态
     * @see PromotionsStatusEnum
     */
    public String getPromotionStatus() {
        if (endTime == null) {
            return startTime != null ? PromotionsStatusEnum.START.name() : PromotionsStatusEnum.CLOSE.name();
        }
        Date now = new Date();
        if (now.before(startTime)) {
            return PromotionsStatusEnum.NEW.name();
        } else if (endTime.before(now)) {
            return PromotionsStatusEnum.END.name();
        } else if (now.before(endTime)) {
            return PromotionsStatusEnum.START.name();
        }
        return PromotionsStatusEnum.CLOSE.name();
    }
}


